﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

using EnvironmentalMonitor.Support.Business.Manage;
using EnvironmentalMonitor.Support.Business;
using EnvironmentalMonitor.Support.Module;
using EnvironmentalMonitor.Support.Resource;

namespace EnvironmentalMonitor.WebApplication.Manage.Menu
{
    /// <summary>
    /// 同步Json数据页面类
    /// </summary>
    public partial class SyncJson : EnvironmentalMonitor.WebApplication.Abstract.AbstractSaveJson
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.SaveJsonData = new Abstract.SaveJsonData();
            this.SaveJsonData.success = false;

            EnvironmentalMonitor.Support.Module.Manage.User sessionUser = this.Session[Constant.SESSION_KEY_USER] as EnvironmentalMonitor.Support.Module.Manage.User;
            List<EnvironmentalMonitor.Support.Module.Manage.Menu> applicationMenus = this.Application[Constant.APPLICATION_KEY_MENUS] as List<EnvironmentalMonitor.Support.Module.Manage.Menu>;

            MenuBusiness business = new MenuBusiness();
            this.SaveJsonData.success = business.Sync(applicationMenus, sessionUser);
            if (this.SaveJsonData.success)
            {
                this.SaveJsonData.msg = "同步成功！";
            }
            else
            {
                this.SaveJsonData.msg = "同步失败！";
            }

            string json = this.Json();

            this.Response.Write(json);
            this.Response.Flush();
            this.Response.End();
        }
    }
}